Index: comment.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/glossary/comment.php,v
retrieving revision 1.31
diff -u -r1.31 comment.php
--- comment.php 4 Sep 2006 20:37:30 -0000 1.31
+++ comment.php 17 Oct 2006 22:41:02 -0000
@@ -3,39 +3,40 @@
/// This page prints a particular instance of glossary
require_once('../../config.php');
require_once('lib.php');
-
+ include('comment_form.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$eid = required_param('eid', PARAM_INT); // Entry ID
$cid = optional_param('cid', 0, PARAM_INT); // Comment ID
$confirm = optional_param('confirm',0, PARAM_INT); // Confirm the action
$action = optional_param('action','add', PARAM_ALPHA);
-
+
$action = strtolower($action);
-
+
global $USER, $CFG;
-
- if (! $cm = get_coursemodule_from_id('glossary', $id)) {
+
+ if (!$cm = get_coursemodule_from_id('glossary', $id)) {
error('Course Module ID was incorrect');
}
-
- if (! $course = get_record('course', 'id', $cm->course)) {
+
+ if (!$course = get_record('course', 'id', $cm->course)) {
+
error('Course is misconfigured');
}
-
- if (! $glossary = get_record('glossary', 'id', $cm->instance)) {
+
+ if (!$glossary = get_record('glossary', 'id', $cm->instance)) {
error('Course module is incorrect');
}
-
- if (! $entry = get_record('glossary_entries', 'id', $eid)) {
+
+ if (!$entry = get_record('glossary_entries', 'id', $eid)) {
error('Entry is incorrect');
}
-
- if ( $cid ) {
- if (! $comment = get_record('glossary_comments', 'id', $cid)) {
+
+ if ($cid ) {
+ if (!$comment = get_record('glossary_comments', 'id', $cid)) {
error('Comment is incorrect');
}
}
-
+
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -44,7 +45,7 @@
error('Guests are not allowed to post comments', $_SERVER['HTTP_REFERER']);
}
add_to_log($course->id, 'glossary', 'view', "view.php?id=$cm->id", "$glossary->id",$cm->id);
-
+
switch ( $action ){
case 'add':
$straction = get_string('addingcomment','glossary');
@@ -60,43 +61,32 @@
$straction = get_string('addingcomment','glossary');
break;
}
- $strglossaries = get_string('modulenameplural', 'glossary');
- $strglossary = get_string('modulename', 'glossary');
- $strcomments = get_string('comments', 'glossary');
-
- print_header_simple(format_string($glossary->name), '',
- "id\">$strglossaries -> id\">".format_string($glossary->name,true)." -> id&eid=$entry->id\">$strcomments -> " . $straction,
- '', '', true, update_module_button($cm->id, $course->id, $strglossary),
- navmenu($course, $cm));
-
- echo '
';
+$strglossaries = get_string('modulenameplural', 'glossary');
+$strglossary = get_string('modulename', 'glossary');
+$strcomments = get_string('comments', 'glossary');
/// Input section
- if ( $action == 'delete' ) {
- if (($comment->userid <> $USER->id) and !has_capability('mod/glossary:managecomments', $context)) {
- error('You can\'t delete other people\'s comments!');
- }
- if (!$glossary->allowcomments && !has_capability('mod/glossary:managecomments', $context)) {
- error('You can\'t delete comments in this glossary!');
- }
- if ( $confirm ) {
- delete_records('glossary_comments','id', $cid);
-
- print_simple_box_start('center','40%', '#FFBBBB');
- echo ''.get_string('commentdeleted','glossary').'';
- print_simple_box_end();
-
- print_footer($course);
- add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&eid=$entry->id", "$comment->id",$cm->id);
- redirect("comments.php?id=$cm->id&eid=$entry->id");
+if ( $action == 'delete' ) {
+ if (($comment->userid <> $USER->id) and !has_capability('mod/glossary:managecomments', $context)) {
+ error('You can\'t delete other people\'s comments!');
+ }
+ if (!$glossary->allowcomments && !has_capability('mod/glossary:managecomments', $context)) {
+ error('You can\'t delete comments in this glossary!');
+ }
+ if ( $confirm ) {
+ delete_records('glossary_comments','id', $cid);
+ add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&eid=$entry->id", "$comment->id",$cm->id);
+ redirect("comments.php?id=$cm->id&eid=$entry->id");
- } else {
-
- glossary_print_comment($course, $cm, $glossary, $entry, $comment);
-
- print_simple_box_start('center','40%', '#FFBBBB');
- echo '
'.get_string('areyousuredeletecomment','glossary');
+ } else {
+ print_header_simple(format_string($glossary->name), '',
+"id\">$strglossaries -> id\">".format_string($glossary->name,true)." -> id&eid=$entry->id\">$strcomments -> " . $straction,
+'', '', true, update_module_button($cm->id, $course->id, $strglossary),
+navmenu($course, $cm));
+ glossary_print_comment($course, $cm, $glossary, $entry, $comment);
+ print_simple_box_start('center','40%', '#FFBBBB');
+ echo '
'.get_string('areyousuredeletecomment','glossary');
?>
allowcomments && !has_capability('mod/glossary:comment', $context)) {
+ error('You can\'t add/edit comments to this glossary!');
+ }
+ if ( $action == 'edit' ) {
+
+ if (!isset($comment->timemodified)) {
+ $timetocheck = 0;
+ } else {
+ $timetocheck = $comment->timemodified;
}
- } else {
- if (!$glossary->allowcomments && !has_capability('mod/glossary:comment', $context)) {
- error('You can\'t add/edit comments to this glossary!');
- }
- if ( $action == 'edit' ) {
- if (!isset($comment->timemodified)) {
- $timetocheck = 0;
- } else {
- $timetocheck = $comment->timemodified;
- }
- $ineditperiod = ((time() - $timetocheck < $CFG->maxeditingtime) || $glossary->editalways);
- if ( (!$ineditperiod || $USER->id != $comment->userid) and !has_capability('mod/glossary:comment', $context) and $cid) {
- if ( $USER->id != $comment->userid ) {
- error('You can\'t edit other people\'s comments!');
- } elseif (!$ineditperiod) {
- error('You can\'t edit this. Time expired!');
- }
- die;
+ $ineditperiod = ((time() - $timetocheck < $CFG->maxeditingtime) || $glossary->editalways);
+ if ( (!$ineditperiod || $USER->id != $comment->userid) and !has_capability('mod/glossary:comment', $context) and $cid) {
+ if ( $USER->id != $comment->userid ) {
+ error('You can\'t edit other people\'s comments!');
+ } elseif (!$ineditperiod) {
+ error('You can\'t edit this. Time expired!');
}
+ die;
}
+ }
- if ( $confirm and $form = data_submitted() ) {
- trusttext_after_edit($form->text, $context);
+ if ($form = data_submitted() ) {
+ trusttext_after_edit($form->text, $context);
+ $newentry->entryid = $entry->id;
+ $newentry->entrycomment = $form->comment;
+ $newentry->timemodified = time();
- $newentry->entryid = $entry->id;
- $newentry->entrycomment = $form->text;
- $newentry->format = $form->format;
- $newentry->timemodified = time();
-
- if ( $action == 'add' ) {
- $newentry->userid = $USER->id;
-
- if (! $newentry->id = insert_record('glossary_comments', $newentry)) {
- error('Could not insert this new comment');
- } else {
- add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id", $cm->id);
- }
- } else {
- $newentry->id = $form->cid;
- $newentry->userid = $comment->userid;
+ if ( $action == 'add' ) {
+
+ $newentry->userid = $USER->id;
- if (! update_record('glossary_comments', $newentry)) {
- error('Could not update this comment');
- } else {
- add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id",$cm->id);
- }
+ if (! $newentry->id = insert_record('glossary_comments', $newentry)) {
+ error('Could not insert this new comment');
+ } else {
+ add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id", $cm->id);
}
- print_simple_box_start('center','40%', '#FFBBBB');
- echo ''.get_string('commentupdated','glossary').'';
- print_simple_box_end();
-
- print_footer($course);
-
- redirect("comments.php?id=$cm->id&eid=$entry->id");
-
} else {
- /// original glossary entry
- glossary_print_entry($course, $cm, $glossary, $entry, 'approval', '', false);
- echo '
';
+ $newentry->id = $form->cid;
+ $newentry->userid = $comment->userid;
- if ($usehtmleditor = can_use_html_editor()) {
- $defaultformat = FORMAT_HTML;
+ if (! update_record('glossary_comments', $newentry)) {
+ error('Could not update this comment');
} else {
- $defaultformat = FORMAT_MOODLE;
- }
- if (isset($comment) ) {
- $form->text = $comment->entrycomment;
- $form->format = $comment->format;
- } else {
- $form->text = '';
- $form->format = $defaultformat;
- }
- include('comment.html');
-
- if ($usehtmleditor) {
- use_html_editor('text');
+ add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id",$cm->id);
}
}
- }
-
- echo '';
+ redirect("comments.php?id=$cm->id&eid=$entry->id");
- /// Finish the page
- print_footer($course);
-?>
+ } else {
+ print_header_simple(format_string($glossary->name), '',
+ "id\">$strglossaries -> id\">".format_string($glossary->name,true)." -> id&eid=$entry->id\">$strcomments -> " . $straction,
+ '', '', true, update_module_button($cm->id, $course->id, $strglossary),
+ navmenu($course, $cm));
+ /// original glossary entry
+ glossary_print_entry($course, $cm, $glossary, $entry, 'approval', '', false);
+ echo '
';
+ helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
+ echo "
";
+ $mform = new glossary_comment_form('comment.php',compact('form','comment','cm','entry','action'));
+ $mform->display();
+ }
+}
+/// Finish the page
+print_footer($course);
+?>
\ No newline at end of file